<?php
	require_once ("../../config.inc.php");
	require_once ("../../include/mysql.inc.php");
	require_once ("../../include/article.inc.php");
	
	require_once ("../../util/stringUtil.inc.php");
	
// 	substr(strip_tags($row[content], 'p'), 0, INDEX_ARTICLE_CONTENT_LENGTH)
	$articleDao = new Article();
	
	$rows = $articleDao->getLatestN(INDEX_ARTICLE_SIZE);

	$dom = new DOMDocument("1.0","UTF-8");
	$articles = $dom->createElement("articles");
	foreach ($rows as $row) {
		$article = $dom->createElement("article");
		$article->setAttribute("id",$row[id]);
		$title = $dom->createElement("title", $row[title]);
		$content = strip_tags($row[content]);
		$content = htmlspecialchars(StringUtil::chinasuber(strip_tags(htmlspecialchars_decode($content)), INDEX_ARTICLE_CONTENT_LENGTH));
		$content = $dom->createElement("content", $content);
		$time = $dom->createElement("time", $row[time]);
		$adminId = $dom->createElement("adminId", $row[adminId]);
		$top = $dom->createElement("top", $row[top]);
		
		$article->appendChild($title);
		$article->appendChild($content);
		$article->appendChild($time);
		$article->appendChild($adminId);
		$article->appendChild($top);
		
		$articles->appendChild($article);
	}
	
	$dom->appendChild($articles);
	header("Content-type:text/xml");
    $xmlfile = $dom->saveXML();
    file_put_contents("../../xml_data/articles.xml",$xmlfile);
    echo $xmlfile;
	
?>